package com.example.a66666.yuejian.Activity;

import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.CompoundButton;
import android.widget.RadioButton;

import com.example.a66666.yuejian.Fragment.ClubFragment;
import com.example.a66666.yuejian.Fragment.ExerciseFragment;
import com.example.a66666.yuejian.Fragment.IndexFragment;
import com.example.a66666.yuejian.Fragment.MeFragment;
import com.example.a66666.yuejian.Fragment.SharepicFragment;
import com.example.a66666.yuejian.R;

public class MainActivity extends AppCompatActivity {
    private RadioButton exercise,club,index,sharepic,me;
    private FragmentManager fragmentManager;
    private FragmentTransaction fragmentTransaction;
    private ExerciseFragment exercisefragment;
    private ClubFragment clubfragment;
    private IndexFragment indexfragment;
    private SharepicFragment sharepicfragment;
    private MeFragment mefragment;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        exercise=(RadioButton)findViewById(R.id.radiobtn_exercise);
        club=(RadioButton)findViewById(R.id.radiobtn_club);
        index=(RadioButton)findViewById(R.id.radiobtn_index);
        sharepic=(RadioButton)findViewById(R.id.radiobtn_showpic);
        me=(RadioButton)findViewById(R.id.radiobtn_me);


        exercise.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
             @Override
             public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                 if(isChecked){
                     if(exercisefragment==null){
                         exercisefragment=new ExerciseFragment();
                     }
                     fragmentTransaction=fragmentManager.beginTransaction();
                     fragmentTransaction.replace(R.id.frameLayout,exercisefragment);
                     fragmentTransaction.commit();
                 }
             }
         });

        club.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if(isChecked){
                    if(clubfragment==null){
                        clubfragment=new ClubFragment();
                    }
                    fragmentTransaction=fragmentManager.beginTransaction();
                    fragmentTransaction.replace(R.id.frameLayout,clubfragment);
                    fragmentTransaction.commit();
                }
            }
        });

        index.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if(isChecked){
                    if(indexfragment==null){
                        indexfragment=new IndexFragment();
                    }
                    fragmentTransaction=fragmentManager.beginTransaction();
                    fragmentTransaction.replace(R.id.frameLayout,indexfragment);
                    fragmentTransaction.commit();
                }
            }
        });

        sharepic.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if(isChecked){
                    if(sharepicfragment==null){
                        sharepicfragment=new SharepicFragment();
                    }
                    fragmentTransaction=fragmentManager.beginTransaction();
                    fragmentTransaction.replace(R.id.frameLayout,sharepicfragment);
                    fragmentTransaction.commit();
                }
            }
        });

        me.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if(isChecked){
                    if(mefragment==null){
                        mefragment=new MeFragment();
                    }
                    fragmentTransaction=fragmentManager.beginTransaction();
                    fragmentTransaction.replace(R.id.frameLayout,mefragment);
                    fragmentTransaction.commit();
                }
            }
        });

        fragmentManager=getSupportFragmentManager();
        index.setChecked(true);
    }
}
